module ActiveTest #:nodoc:
  module Asserts #:nodoc:
    module Assigns
      
      # Assert that an instance variable has been assigned to the template. Takes
      # an optional value for assert_equal.
      #   assert_assigned :items, [1,3,5]
      def assert_assigned(symbol, value = nil)
        if value
          assert_equal assigns(symbol), value, "#{symbol} should equal #{value.inspect}"
        else
          assert assigns(symbol), "#{symbol} should be set"
        end
      end

      # Asserts, by default, that an instance variable has not been assigned to the
      # template. Takes an optional value to which the instance variable is not equal.
      #   assert_not_assigned :apples
      #   assert_not_assigned :fruits, [:apples]
      def assert_not_assigned(symbol, value = nil)
        if value
          assert_not_equal assigns(symbol), value, "#{symbol} should not be #{value.inspect}"
        else
          assert assigns(symbol).nil?, "#{symbol} should not be set"
        end
      end
      
      # Assuming that the assignment to the template is enumerable, assert_assign_includes
      # asserts a certain value is included in the enumeration.
      #   assert_assign_includes :fruits, :apples
      def assert_assign_includes(symbol, value)
        assert assigns(symbol).is_a?(Enumerable), "#{symbol} is not enumerable."
        assert assigns(symbol).include?(value), "#{symbol} does not have #{value.inspect}"
      end
      
      # Assuming that the assignment to the template is enumerable, assert_assign_excludes
      # asserts a certain value is not included in the enumeration.
      #   assert_assign_excludes :fruits, :apples
      def assert_assign_excludes(symbol, value)
        assert assigns(symbol).is_a?(Enumerable), "#{symbol} is not enumerable."
        assert !assigns(symbol).include?(value), "#{symbol} includes #{value.inspect}"
      end

    end
  end
end